package org.example.service;

import jakarta.annotation.Resource;
import org.example.entity.MyUser;
import org.example.entity.MyUserDetails;
import org.example.mapper.UserMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyUserDetailsService implements UserDetailsService {


    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        MyUser myUser = userMapper.getUserByName(username);
        List<String> authorityList = userMapper.getAuthorityList(myUser.getUserId());
        MyUserDetails userDetails = new MyUserDetails(myUser, authorityList);
        return userDetails;
    }
}
